package com.pine.generator;

import com.pine.generator.config.GeneratorCodeConfig;
import com.pine.generator.config.ProjectStructConfig;
import org.yaml.snakeyaml.Yaml;

import java.io.InputStream;

public class Client {
    public static final String GENERATOR_CONFIG_YAML_FILE_NAME = "generatorConfig.yaml";

    public static void main(String[] args) {
        // 获取当前项目对应的目录
        String userDir = System.getProperty("user.dir");

        // 解析YAML文件
        InputStream yamlInputStream = getGeneratorConfigYamlInputStream();
        Yaml yaml = new Yaml();

        // 生成器的通用配置信息
        GeneratorCodeConfig generatorCodeConfig = yaml.loadAs(yamlInputStream, GeneratorCodeConfig.class);
        ProjectStructConfig projectStructConfig = generatorCodeConfig.getProjectStructConfig();
        projectStructConfig.setDirectory(userDir + "/" + projectStructConfig.getDirectory() + "/");

        GenerateCodeExecutor executor = new GenerateCodeExecutor();
        // 设置表名
        generatorCodeConfig.setTableName("sys_approval_application");
        generatorCodeConfig.getEnumNameMap().put("status", "ApprovalStatusEnum");
        executor.execute(generatorCodeConfig);
    }



    public static InputStream getGeneratorConfigYamlInputStream() {
        return Client.class.getClassLoader().getResourceAsStream(GENERATOR_CONFIG_YAML_FILE_NAME);
    }
}
